import { MenuVoInfo } from '#/entity.ts';

export const flattenPermission = (treePermission: MenuVoInfo[]) => {
  return treePermission.reduce<string[]>((prev, item) => {
    const { menuPath, childrenMenu } = item;
    prev.push(menuPath);
    if (childrenMenu && childrenMenu.length) {
      prev.push(...flattenPermission(childrenMenu));
    }
    return prev;
  }, []);
};
